home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / execd1200.iso / Shareware / Blocks 3 / setup.exe / Source / PART.C < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-25  |  1.5 KB  |  79 lines

  1. #include <allegro.h>
  2. #include <blocks3.h>
  3.  
  4. int counter;
  5.  
  6. void Add_Part(int x, int y, int dx, int dy, int col)
  7. {
  8.  part[part_count].x = x;
  9.  part[part_count].y = y;
  10.  part[part_count].dx = dx;
  11.  part[part_count].dy = dy;
  12.  part[part_count].col = col;
  13.  
  14.  part_count++;
  15. }
  16.  
  17. void Del_Part(int p_no)
  18. {
  19.  int i;
  20.  
  21.  for (i = p_no; i < part_count; i++)
  22.  {
  23.   part[i].x = part[i + 1].x;
  24.   part[i].y = part[i + 1].y;
  25.   part[i].dx = part[i + 1].dx;
  26.   part[i].dy = part[i + 1].dy;
  27.   part[i].col = part[i + 1].col;
  28.  }
  29.  
  30.  part_count--;
  31. }
  32.  
  33. void Particle(void)
  34. {
  35.  if (part_count < 999)
  36.  {
  37.   if (rand()%2 == 1) Add_Part(320 + rand()%16, 200 + rand()%32, (rand()%50 + 20), -(rand()%10 + 5), rand()%255);
  38.   else  Add_Part(320 + rand()%16, 200 + rand()%32, -(rand()%50 + 20), -(rand()%10 + 5), rand()%255);
  39.  }
  40.  
  41.  Particle_Move();
  42. }
  43.  
  44. void Particle_Move(void)
  45. {
  46.  int i;
  47.  
  48.  counter++;
  49.  
  50.  if (counter > 50) counter = 0;
  51.  
  52.  for (i = 0; i < part_count; i++)
  53.  {
  54.   putpixel(screen, part[i].x, part[i].y, getpixel(temp, part[i].x, part[i].y));
  55.  
  56.   if (!(counter%part[i].dx)) part[i].x += part[i].dx/abs(part[i].dx);
  57.   if (!(counter%part[i].dy)) part[i].y += part[i].dy/abs(part[i].dy);
  58.  
  59.   part[i].col++;
  60.  
  61.   if (part[i].col == 256)
  62.   {
  63.    Del_Part(i);
  64.    i--;
  65.   }
  66.   else
  67.   {
  68.    putpixel(screen, part[i].x, part[i].y, makecol8(255, 255 - part[i].col, 255 - part[i].col));
  69.  
  70.    if ((part[i].col > 100) && (part_count < 900))
  71.    {
  72.     Add_Part(part[i].x, part[i].y + 1, part[i].dx, part[i].dy, part[i].col);
  73.    }
  74.   }
  75.  }
  76. }
  77.  
  78.  
  79.